// app/models/userModel.js

const db = require('./db');

class UserModel {
  // 获取所有用户
  getAllUsers(callback) {
    const query = 'SELECT * FROM users';
    db.query(query, callback);
  }

  // 根据 ID 获取用户
  getUserById(id, callback) {
    const query = 'SELECT * FROM users WHERE id = ?';
    db.query(query, [id], callback);
  }

  // 创建新用户
  createUser(name, age, email, callback) {
    const query = 'INSERT INTO users (name, age, email) VALUES (?, ?, ?)';
    db.query(query, [name, age, email], callback);
  }

  // 更新用户
  updateUser(id, name, age, email, callback) {
    const query = 'UPDATE users SET name = ?, age = ?, email = ? WHERE id = ?';
    db.query(query, [name, age, email, id], callback);
  }

  // 删除用户
  deleteUser(id, callback) {
    const query = 'DELETE FROM users WHERE id = ?';
    db.query(query, [id], callback);
  }
}

module.exports = new UserModel();